//逃亡的准备 一维多重背包
#include <iostream>
using namespace std;
const int MAXN=2000;
const int MAXV=500;
int n,v;
int m[MAXN+1],w[MAXN+1],s[MAXN+1];
int maxs[MAXV+1];

int main(){
    cin>>n>>v;
    for(int i=1;i<=n;i++) cin>>m[i]>>w[i]>>s[i];

    /* for(int i=1;i<=n;i++)
        for(int v1=v;v1>=w[i];v1--)
            for(int k=1;k<=min(m[i],v1/w[i]);k++)
                if (maxs[v1]<maxs[v1-k*w[i]]+k*s[i]) maxs[v1]=maxs[v1-k*w[i]]+k*s[i]; */
    //采用二进制优化
    for(int i=1;i<=n;i++)
        for(int k=0,p=1;p<=m[i];k++,p=1<<k){
            if (p*2>m[i]) p=m[i]-p+1;
            for(int v1=v;v1>=p*w[i];v1--)
                if (maxs[v1]<maxs[v1-p*w[i]]+p*s[i]) maxs[v1]=maxs[v1-p*w[i]]+p*s[i];
        }
    cout<<maxs[v];
}